<?php


/**
 * View plugin.
 */
class Main_View extends Psa_Plugin_View{

	
	/**
	 * Login form.
	 */
	function login(){
		
		$this->psa_smarty->assign("content", $this->psa_smarty->fetch("example_app2/login.tpl"));
	}

	
	/**
	 * First page.
	 */
	function index(){

		$this->psa_smarty->assign("content", $this->psa_smarty->fetch("example_app2/index.tpl"));
	}


	/**
	 * Main template render and display method.
	 */
	function generate_html($only_content = null){

		// if this is ajax request just echo psa_result->content_ajax value
		if(@$this->psa_result->ajax_request){
			header("Content-Type: text/html; charset=utf-8");
			if(isset($this->psa_smarty->_tpl_vars["content"]))
				echo $this->psa_smarty->_tpl_vars["content"];
		}
		// render complete page
		else{
			
			if(!$only_content){
				$this->psa_smarty->assign("header", $this->psa_smarty->fetch("example_app2/header.tpl"));
				$this->psa_smarty->assign("menu", $this->psa_smarty->fetch("example_app2/menu.tpl"));
			}
			
			echo $this->psa_smarty->fetch("example_app2/main.tpl");
			
			// show request info only in develop modeS
			global $PSA_CFG;
			if($PSA_CFG['develop_mode'])
				echo psa_request_info_html();
		}
	}


	/**
	 * Forward browser to error page. (validation_exeption action)
	 */
	function location_validation_exception(){

		global $PSA_CFG;
		header("Location: {$PSA_CFG['folders']['basedir_web']}/app2/validation_exeption/");
		exit();
	}


	/**
	 * Error message for Psa_Validation_Exception.
	 */
	function validation_exception(){

		$this->psa_smarty->assign("error_msg", "Error in input values.");
		$this->psa_smarty->assign("content", $this->psa_smarty->fetch("example_app2/error.tpl"));
	}

	/**
	 * Forward browser to error page. (unpermitted_action_exception action)
	 */
	function location_unpermitted_action_exception(){

		global $PSA_CFG;
		header("Location: {$PSA_CFG['folders']['basedir_web']}/app2/unpermitted_action_exception/");
		exit();
	}

	/**
	 * Error message for Unpermitted_Action_Exception.
	 */
	function unpermitted_action_exception(){
		
		$this->psa_smarty->assign("error_msg", "Error. You don't have permission to access this page.");
		$this->psa_smarty->assign("content", $this->psa_smarty->fetch("example_app2/error.tpl"));
	}
}

?>